Crate rustc_apfloat
source ·Expand description
Port of LLVM’s APFloat software floating-point implementation from the following C++ sources (please update commit hash when backporting): https://github.com/llvm/llvm-project/commit/462a31f5a5abb905869ea93cc49b096079b11aa4
llvm/include/llvm/ADT/APFloat.h
->Float
andFloatConvert
traitsllvm/lib/Support/APFloat.cpp
->ieee
andppc
modulesllvm/unittests/ADT/APFloatTest.cpp
->tests
directory
The port contains no unsafe code, global state, or side-effects in general, and the only allocations are in the conversion to/from decimal strings.
Most of the API and the testcases are intact in some form or another,
with some ergonomic changes, such as idiomatic short names, returning
new values instead of mutating the receiver, and having separate method
variants that take a non-default rounding mode (with the suffix _r
).
Comments have been preserved where possible, only slightly adapted.
Instead of keeping a pointer to a configuration struct and inspecting it
dynamically on every operation, types (e.g. ieee::Double
), traits
(e.g. ieee::Semantics
) and associated constants are employed for
increased type safety and performance.
On-heap bigints are replaced everywhere (except in decimal conversion),
with short arrays of type Limb = u128
elements (instead of u64
),
This allows fitting the largest supported significands in one integer
(ieee::Quad
and ppc::Fallback
use slightly less than 128 bits).
All of the functions in the ieee::sig
module operate on slices.
§Note
This API is completely unstable and subject to change.
Modules§
- Support for floating point types compatible with IEEE 754.
- Support for floating point types that use PowerPC semantics.
Macros§
Structs§
- An error which can occur when parsing a floating point number from a string.
- IEEE-754R 7: Default exception handling.
- The result of a computation consisting of the output value and the exceptions, if any.
Enums§
- Category of internally-represented number.
- IEEE-754R 4.3: Rounding-direction attributes.
Constants§
Traits§
- A self-contained host- and target-independent arbitrary-precision floating-point software implementation.
- Convert between floating point types.
Type Aliases§
- A signed type to represent a floating point number’s unbiased exponent.